using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace SBPweb.Controls.Windows.Form
{
	/// <summary>
	/// Class of ProgressForm
	/// </summary>
	[ToolboxBitmap(typeof(System.Windows.Forms.MessageBox))]
	public partial class ProgressForm : SBPweb.Controls.Windows.Common.Form
	{
		private Color mColorFrom = Color.White;
		private Color mColorTo = Color.LightGreen;
		private LinearGradientBrush mBrush = null;
		private int mPosition = 0;
		private bool mGo = true;
		private Timer mTimer;

		public ProgressForm()
		{
			InitializeComponent();
			base.FormBorderStyle = FormBorderStyle.FixedToolWindow;
			this.BackgroundImage = global::SBPweb.Controls.Windows.Properties.Resources.Back_01_1x200;
			SetBrush();

			pBar.MarqueeAnimationSpeed = 1000;

			mTimer = new Timer();
			mTimer.Tick += new EventHandler(timer_Tick);
			mTimer.Interval = 100;
			mTimer.Enabled = true;
		}

		[Browsable(false)]
		public new FormBorderStyle FormBorderStyle
		{
			get
			{
				return base.FormBorderStyle;
			}
		}

		[Category("Appearance")]
		public string Caption
		{
			get
			{
				return lCaption.Text;
			}
			set
			{
				lCaption.Text = value;
			}
		}

		[Category("Appearance")]
		public Color ColorFrom
		{
			get
			{
				return mColorFrom;
			}
			set
			{
				mColorFrom = value;
				SetBrush();
			}
		}

		[Category("Appearance")]
		public Color ColorTo
		{
			get
			{
				return mColorTo;
			}
			set
			{
				mColorTo = value;
				SetBrush();
			}
		}

		private void SetBrush()
		{
			Rectangle rect = new Rectangle(this.ClientRectangle.Left - this.ClientRectangle.Width, this.ClientRectangle.Left - this.ClientRectangle.Width, this.ClientRectangle.Width * 2, this.ClientRectangle.Width * 2);
			mBrush = new LinearGradientBrush(rect, mColorFrom, mColorTo, LinearGradientMode.ForwardDiagonal);
			pBar.ForeColor = mColorTo;
		}

		protected override void OnPaint(PaintEventArgs e)
		{
			base.OnPaint(e);
			if (this.BackgroundImage != null)
			{
				e.Graphics.DrawImage(this.BackgroundImage, this.ClientRectangle);
			}
		}

		protected override void OnPaintBackground(PaintEventArgs e)
		{
			base.OnPaintBackground(e);

			e.Graphics.FillRectangle(mBrush, this.ClientRectangle);
		}

		private void DoProgress()
		{
			mPosition++;

			if (mPosition > 360)
			{
				mPosition = 0;
				mGo = !mGo;
			}

			if (mGo)
			{
				mBrush.RotateTransform(3.0F);
			}
			else
			{
				mBrush.RotateTransform(-3.0F);
			}

			pBar.Value = mPosition;

			Invalidate();
		}

		protected override void OnVisibleChanged(EventArgs e)
		{
			base.OnVisibleChanged(e);
			mTimer.Enabled = this.Visible;
		}

		private void timer_Tick(object sender, EventArgs e)
		{
			DoProgress();
		}

	}
}